$(function(){
	// 基本资料保存
	$('#setSave').click(function() {
		// alert(222);
		var form = $('#jbzl form');
		var data = {
			sex: form.find('input[name=sex]:checked').val(),
			address:form.find('input[name=address]').val(),
			work:form.find('input[name=work]').val(),
			school:form.find('input[name=school]').val(),
			autograph:form.find('input[name=autograph]').val(),
			intro:form.find('input[name=intro]').val()
		};
		$.ajax({
            url: '/api/setting',
            type: 'post',
            dataType: 'json',
            data: data,
            async:false,
            success:function(res){
                if(res == '1'){
                	$('#notice').html('保存成功!!!');
                	$('#noticeModal').modal();
                }else{
                	$('#notice').html('保存失败!!! 请重试......');
                	$('#noticeModal').modal();
                }
            }
		});
	});
	$('input[name=name]').blur(function(){
		var v = $(this).val();
		var data = {name:v};
		$.post('/api/change', data, function(res){
			if(res.status == '1'){
            	$('#notice').html('保存成功!!!');
            	$('#noticeModal').modal();
            }else{
            	$('#notice').html('保存失败!!! 请重试......');
            	$('#noticeModal').modal();
            }
		});
	});
	$('.changeEmail').click(function(){
		var v = $(this).prev().text();
		$(this).prev('span').remove();
		$(this).remove();
		$('input[name=email]').show();
	});
	$('.changePhone').click(function(){
		var v = $(this).prev().text();
		$(this).prev('span').remove();
		$(this).remove();
		$('input[name=phone]').show();
	});
	$('input[name=email]').blur(function(){
		var v = $(this).val();
		var data = {email:v};
		$.post('/api/change', data, function(res){
			if(res.status == '1'){
            	$('#notice').html('保存成功!!!');
            	$('#noticeModal').modal();
            }else{
            	$('#notice').html('保存失败!!! 请重试......');
            	$('#noticeModal').modal();
            }
		});
	});
	$('input[name=phone]').blur(function(){
		var v = $(this).val();
		var data = {phone:v};
		$.post('/api/change', data, function(res){
			if(res.status == '1'){
            	$('#notice').html('保存成功!!!');
            	$('#noticeModal').modal();
            }else{
            	$('#notice').html('保存失败!!! 请重试......');
            	$('#noticeModal').modal();
            }
		});
	});
	// 头像上传
	var uploader = new plupload.Uploader({
		browse_button:'setFace',
		url:'/api/setFace'
	});
	uploader.init();
	uploader.bind('FilesAdded',function(uploader,files){
    	uploader.start();
    });
    uploader.bind('FileUploaded',function(uploader,files, res){
    	if(res != '0'){
	    	var img = res.response;
	    	$('#setFace').attr('src', img);
    	}
    });
});